<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/11/3
 * Time: 22:10
 */

namespace app\services\face;


use think\facade\Config;

class SmsService {
    public static function sms($mobile , $con)
    {
        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );



        $config = [
            'sign' => '汇安学校线上学习平台' ,
            'number' => '13785185620' ,
            'password' => '13785185620' ,
        ] ;
        $smsapi = "http://api.smsbao.com/";
        $user = $config['number']; //短信平台帐号
        $pass = md5($config['password']); //短信平台密码
        $content="【".$config['sign']."】您的验证码是{$con}。如非本人操作，请忽略本短信";//要发送的短信内容
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$mobile."&c=".urlencode($content);
        $result = self::curlGet($sendurl) ;
        return true ;
    }
    public static function curlGet($url )
    {

        $curl = curl_init();
        //设置抓取的url
        curl_setopt($curl, CURLOPT_URL, $url);
        //设置头文件的信息作为数据流输出
        curl_setopt($curl, CURLOPT_HEADER, 0);
        // 超时设置,以秒为单位
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);

        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 3);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        //执行命令
        $data = curl_exec($curl);
        // 显示错误信息
        if (curl_error($curl)) {
            print "Error: " . curl_error($curl);
        } else {
            curl_close($curl);
            return $data ;
        }
    }
}